//
//  YXSettingViewController.m
//  MockProject
//
//  Created by 周丽丽 on 16/8/24.
//  Copyright © 2016年 niuzhaowang. All rights reserved.
//

#import "YXSettingViewController.h"
#import "YXSettingModel.h"
#import "YXGeneralSettingsViewController.h"
#import "YXMoreAboutViewController.h"
@interface YXSettingViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *settingTableView;
@property (nonatomic, strong) NSArray *settingModelsArr;
@end

@implementation YXSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"";
    self.navigationItem.title = @"设置";
    UITableView *settingTableV = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    [self.view addSubview:settingTableV];
    settingTableV.delegate = self;
    settingTableV.dataSource = self;
    [self setupSettingModelsArr];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.settingModelsArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *settingCellID =@"settingCellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:settingCellID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:settingCellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    YXSettingModel *model = self.settingModelsArr[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:model.icon];
    cell.textLabel.text = model.title;
    cell.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:model.auxiliaryImg]];
    return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        self.hidesBottomBarWhenPushed=YES;
        YXGeneralSettingsViewController *generalSettingsVC = [[YXGeneralSettingsViewController alloc]init];
        [self.navigationController pushViewController:generalSettingsVC animated:YES];
        self.hidesBottomBarWhenPushed=NO;
    }else if (indexPath.row == 1){
        self.hidesBottomBarWhenPushed=YES;
        YXMoreAboutViewController *moreAboutVC = [[YXMoreAboutViewController alloc]init];
        [self.navigationController pushViewController:moreAboutVC animated:YES];
        self.hidesBottomBarWhenPushed=NO;
    }
}
- (void)setupBackButton{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 30, 30);
    [backBtn setImage:[UIImage imageNamed:@"返回按钮正常态"] forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"返回按钮-点击态"] forState:UIControlStateSelected];
    [backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backItem;
}
-(void)doBack:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)setupSettingModelsArr{
    NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Setting.plist" ofType:nil]];
    NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:array.count];
    for (NSDictionary *dict in array) {
        [arrayM addObject:[[YXSettingModel alloc]initWithDictionary:dict error:nil]];
    }
    self.settingModelsArr = arrayM.copy;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
